home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.text;
-
- import java.io.Serializable;
- import java.util.Enumeration;
- import java.util.Hashtable;
-
- public class SimpleAttributeSet implements MutableAttributeSet, Serializable {
- public static final AttributeSet EMPTY = new SimpleAttributeSet();
- private Hashtable table = new Hashtable(3);
-
- public SimpleAttributeSet() {
- }
-
- public SimpleAttributeSet(AttributeSet source) {
- this.addAttributes(source);
- }
-
- private SimpleAttributeSet(Hashtable table) {
- this.table = table;
- }
-
- public void addAttribute(Object name, Object value) {
- this.table.put(name, value);
- }
-
- public void addAttributes(AttributeSet attributes) {
- Enumeration names = attributes.getAttributeNames();
-
- while(names.hasMoreElements()) {
- Object name = names.nextElement();
- this.addAttribute(name, attributes.getAttribute(name));
- }
-
- }
-
- public Object clone() {
- return new SimpleAttributeSet((Hashtable)this.table.clone());
- }
-
- public boolean containsAttribute(Object name, Object value) {
- return value.equals(this.getAttribute(name));
- }
-
- public boolean containsAttributes(AttributeSet attributes) {
- boolean result = true;
-
- Object name;
- for(Enumeration names = attributes.getAttributeNames(); result && names.hasMoreElements(); result = attributes.getAttribute(name).equals(this.getAttribute(name))) {
- name = names.nextElement();
- }
-
- return result;
- }
-
- public AttributeSet copyAttributes() {
- return (AttributeSet)this.clone();
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof AttributeSet) {
- AttributeSet attrs = (AttributeSet)obj;
- return this.isEqual(attrs);
- } else {
- return false;
- }
- }
-
- public Object getAttribute(Object name) {
- Object value = this.table.get(name);
- if (value == null) {
- AttributeSet parent = this.getResolveParent();
- if (parent != null) {
- value = parent.getAttribute(name);
- }
- }
-
- return value;
- }
-
- public int getAttributeCount() {
- return this.table.size();
- }
-
- public Enumeration getAttributeNames() {
- return this.table.keys();
- }
-
- public AttributeSet getResolveParent() {
- return (AttributeSet)this.table.get(StyleConstants.ResolveAttribute);
- }
-
- public int hashCode() {
- return this.table.hashCode();
- }
-
- public boolean isDefined(Object attrName) {
- return this.table.containsKey(attrName);
- }
-
- public boolean isEmpty() {
- return this.table.isEmpty();
- }
-
- public boolean isEqual(AttributeSet attr) {
- return this.getAttributeCount() == attr.getAttributeCount() && this.containsAttributes(attr);
- }
-
- public void removeAttribute(Object name) {
- this.table.remove(name);
- }
-
- public void removeAttributes(AttributeSet attributes) {
- Enumeration names = attributes.getAttributeNames();
-
- while(names.hasMoreElements()) {
- Object name = names.nextElement();
- Object value = attributes.getAttribute(name);
- if (value.equals(this.getAttribute(name))) {
- this.removeAttribute(name);
- }
- }
-
- }
-
- public void removeAttributes(Enumeration names) {
- while(names.hasMoreElements()) {
- this.removeAttribute(names.nextElement());
- }
-
- }
-
- public void setResolveParent(AttributeSet parent) {
- this.addAttribute(StyleConstants.ResolveAttribute, parent);
- }
-
- public String toString() {
- String s = "";
- Enumeration names = this.getAttributeNames();
-
- while(names.hasMoreElements()) {
- Object key = names.nextElement();
- Object value = this.getAttribute(key);
- if (value instanceof AttributeSet) {
- s = s + key + "=**AttributeSet** ";
- } else {
- s = s + key + "=" + value + " ";
- }
- }
-
- return s;
- }
- }
-